#ifndef ACEMESH_LDMQUEUE_H
#define ACEMESH_LDMQUEUE_H
#include "task.h"
#include "am_assert.h"
#include "slave.h"

#define LDM_QUEUE_SIZE 32

//#define LOCAL_MULTI_SIZE 4

void slave_ldmq_push(struct task* t);
//int slave_ldmq_trypop(struct task** t);

#ifdef LOCAL_MULTI_PRIORI
#define ldmq_empty(dest_qid) (ldmq_full[dest_qid]?0:((top[dest_qid]==bottom[dest_qid])?1:0))

// inlined version
//two parameters: struct task * t, int succ
#define  slave_ldmq_trypop(t, succ, dest_qid) \
{    \
  t=NULL; \
  if(!ldmq_empty(dest_qid)){  \
    top[dest_qid]=(top[dest_qid] -1+LDM_QUEUE_SIZE)%LDM_QUEUE_SIZE; \
    t=ldmqueue[dest_qid][top[dest_qid]];							\
    AM_output1("ldmq_popx...");					\
    ldmq_full[dest_qid]=0;								\
    succ= 1;									\
  }else												\
    succ= 0;  \
}
#else
#define ldmq_empty (ldmq_full?0:((top==bottom)?1:0))

// inlined version
//two parameters: struct task * t, int succ
#define  slave_ldmq_trypop(t, succ) \
{    \
  t=NULL; \
  if(!ldmq_empty){  \
    top=(top -1+LDM_QUEUE_SIZE)%LDM_QUEUE_SIZE; \
    t=ldmqueue[top];							\
    AM_output1("ldmq_popx...");					\
    ldmq_full=0;								\
    succ= 1;									\
  }else												\
    succ= 0;  \
}


#endif

#endif
